package settings
{
	import flash.display.BitmapData;
	import flash.net.SharedObject;
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	
	
	public class Settings
	{
		public function Settings()
		{
			
		}
		
		public static const VERSION:Number=1;
		
		public var favourites:Vector.<String>=new Vector.<String>();
		
		public var favouritesBitmapData:Vector.<BitmapDataSerializer>=new Vector.<BitmapDataSerializer>();
		
		public function removeFavourite(id:int):void {
			favourites.splice(id,1);
			favouritesBitmapData.splice(id,1);
			saveSettings(this);
		}
		
		public var homeURL:String="http://google.com";
		
		private static var _so:SharedObject;
		public static function loadSettings():Settings{
			registerClassAlias("SettingsManager.Settings",Settings);
			registerClassAlias("SerializableBitmapData",BitmapDataSerializer);
			registerClassAlias("String",String);
			_so=SharedObject.getLocal("settings","/");
			if(_so.data==null||_so.data.version!=Settings.VERSION){
				_so.clear();
				_so.data.version=Settings.VERSION;
				_so.data.settings=new Settings();
				_so.flush();
				return Settings(_so.data.settings);
			}
			else{
				return Settings(_so.data.settings);
			}
		}
		
		public static function saveSettings(newSettings:Settings):void{
			_so.data.version=Settings.VERSION;
			_so.data.settings=newSettings;
			_so.flush();
		}
		
	}
}